package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author
 * @date 2021/01/25
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;

    /**
     * 评论列表
     * GET /comments
     */
    @GetMapping
    public ResponseEntity findCommentsList(String movementId, int page, int pagesize){
        return commentsService.findCommentsList(movementId, page, pagesize);
    }

    /**
     * 动态-发表评论
     * POST /comments
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map map) {
        String publishId = (String) map.get("movementId");
        String content = (String) map.get("comment");
        return commentsService.saveComment(publishId, content);
    }
}